home *** CD-ROM | disk | FTP | other *** search
/ What PC? 1998 December / WPCDEC98.ISO / dxrs / Mainmn12.dxr / internet_27_Netscape-specific cut-n-paste Lingo handlers.ls < prev    next >
Encoding:
Text File  |  1998-10-12  |  12.6 KB  |  351 lines

  1. on tellNetscapeURL theURL
  2.   global gMasterAppObject
  3.   if not insureMasterApp() then
  4.     warning("tellNetscapeURL(): insureMasterApp() failed")
  5.     return 0
  6.   end if
  7.   set nsID to 0
  8.   set nsIDs to netscapeWindowIDs()
  9.   set theCount to count(nsIDs)
  10.   if theCount > 1 then
  11.     killAllNetscapeTasks()
  12.   else
  13.     if theCount = 1 then
  14.       set nsID to getAt(nsIDs, 1)
  15.     end if
  16.   end if
  17.   if nsID = 0 then
  18.     set nsPath to gMasterAppObject(mLocateExecutable, "netscape.exe")
  19.     if word 1 of nsPath = "Error:" then
  20.       set nsPath to getExtensionApp("htm")
  21.       if word 1 of nsPath = "Error:" then
  22.         warning("tellNetscapeURL(): no application registered to handle .htm files")
  23.         return "Error: no application registered to handle .htm files"
  24.       end if
  25.       set justFile to fileOnly(nsPath)
  26.       if not (justFile contains "netscape") then
  27.         warning("tellNetscape(): something other than Netscape handles .htm files")
  28.         return "Error: something other than Netscape handles .htm files"
  29.       end if
  30.     end if
  31.     set nsModuleID to gMasterAppObject(mLaunchButDontActivate, nsPath, EMPTY)
  32.     if nsModuleID < 32 then
  33.       warning("tellNetscape(): problem launching Netscape (" & nsModuleID & ")")
  34.       return "Error: tellNetscape(): problem launching Netscape (" & nsModuleID & ")"
  35.     end if
  36.     set giveUpTicks to the ticks + (15 * 60)
  37.     set Ok to 0
  38.     repeat while 1
  39.       set nsIDs to netscapeWindowIDs()
  40.       set theCount to count(nsIDs)
  41.       if theCount > 0 then
  42.         set Ok to 1
  43.         exit repeat
  44.       end if
  45.       gMasterAppObject(mFeedGenericTimeSlice)
  46.     end repeat
  47.     if not (Ok = 1) then
  48.       warning("tellNetscape(): fifteen second timeout after launching Netscape")
  49.       return "Error: tellNetscape(): fifteen second timeout after launching Netscape"
  50.     end if
  51.     set nsID to getAt(nsIDs, 1)
  52.     set giveUpTicks to the ticks + (10 * 60)
  53.     repeat while the ticks < giveUpTicks
  54.       gMasterAppObject(mFeedGenericTimeSlice)
  55.     end repeat
  56.   end if
  57.   set theTask to gMasterAppObject(mGetWindowTask, nsID)
  58.   gMasterAppObject(mWindowToFront, nsID)
  59.   gMasterAppObject(mFeedTimeSlice, theTask)
  60.   gMasterAppObject(mFeedGenericTimeSlice)
  61.   set giveUpTicks to the ticks + (0.5 * 60)
  62.   repeat while the ticks < giveUpTicks
  63.     gMasterAppObject(mFeedTimeSlice, theTask)
  64.     gMasterAppObject(mFeedGenericTimeSlice)
  65.   end repeat
  66.   set theFront to gMasterAppObject(mGetTaskWindowIDs, theTask)
  67.   if word 1 of theFront <> "Error:" then
  68.     set nt to the number of words in theFront
  69.     if nt >= 1 then
  70.       repeat with i = 1 to nt
  71.         set thisFrontText to word i of theFront
  72.         set thisFrontID to integer(thisFrontText)
  73.         if integerp(thisFrontID) then
  74.           if gMasterAppObject(mWindowIsVisible, thisFrontID) then
  75.             if gMasterAppObject(mWindowName, thisFrontID) <> EMPTY then
  76.               if gMasterAppObject(mWindowParent, thisFrontID) = nsID then
  77.                 set kidsText to gMasterAppObject(mGetChildWindowIDs, thisFrontID)
  78.                 if word 1 of kidsText <> "Error:" then
  79.                   set nw to the number of words in kidsText
  80.                   if nw > 1 then
  81.                     repeat with j = 1 to nw
  82.                       set thisKidText to word j of kidsText
  83.                       set thisKid to integer(thisKidText)
  84.                       if integerp(thisKid) then
  85.                         if gMasterAppObject(mWindowName, thisKid) = "Cancel" then
  86.                           set theRect to gMasterAppObject(mGetWindowInsideRect, thisKid)
  87.                           set x to (integer(word 1 of theRect) + integer(word 3 of theRect)) / 2
  88.                           set y to (integer(word 2 of theRect) + integer(word 4 of theRect)) / 2
  89.                           gMasterAppObject(mFakeMouseClick, thisKid, x, y)
  90.                           gMasterAppObject(mFeedTimeSlice, theTask)
  91.                           gMasterAppObject(mFeedGenericTimeSlice)
  92.                         end if
  93.                       end if
  94.                     end repeat
  95.                   end if
  96.                 end if
  97.               end if
  98.             end if
  99.           end if
  100.         end if
  101.       end repeat
  102.     end if
  103.   end if
  104.   gMasterAppObject(mShowMenu, nsID)
  105.   set giveUpTicks to the ticks + (0.25 * 60)
  106.   repeat while the ticks < giveUpTicks
  107.     gMasterAppObject(mFeedTimeSlice, theTask)
  108.     gMasterAppObject(mFeedGenericTimeSlice)
  109.   end repeat
  110.   gMasterAppObject(mFakeCharacter, nsID, "f")
  111.   set giveUpTicks to the ticks + (0.25 * 60)
  112.   repeat while the ticks < giveUpTicks
  113.     gMasterAppObject(mFeedTimeSlice, theTask)
  114.     gMasterAppObject(mFeedGenericTimeSlice)
  115.   end repeat
  116.   gMasterAppObject(mFakeCharacter, nsID, "l")
  117.   set giveUpTicks to the ticks + (0.25 * 60)
  118.   repeat while the ticks < giveUpTicks
  119.     gMasterAppObject(mFeedTimeSlice, theTask)
  120.     gMasterAppObject(mFeedGenericTimeSlice)
  121.   end repeat
  122.   set taskWindowIDs to gMasterAppObject(mGetTaskWindowIDs, theTask)
  123.   if word 1 of taskWindowIDs = "Error:" then
  124.     warning("tellNetscapeURL(): error identifying Open Location dialog.")
  125.     return "Error: tellNetscapeURL(): error identifying Open Location dialog"
  126.   end if
  127.   set ncw to the number of words in taskWindowIDs
  128.   set olDialog to 0
  129.   if ncw >= 1 then
  130.     repeat with i = 1 to ncw
  131.       set thisWindowText to word i of taskWindowIDs
  132.       set thisWindow to integer(thisWindowText)
  133.       if integerp(thisWindow) then
  134.         if gMasterAppObject(mWindowName, thisWindow) = "Open Location" then
  135.           set olDialog to thisWindow
  136.         end if
  137.       end if
  138.     end repeat
  139.   end if
  140.   if olDialog = 0 then
  141.     warning("tellNetscapeURL(): can't find Open Location dialog")
  142.     return "Error: tellNetscapeURL(): can't find Open Location dialog"
  143.   end if
  144.   set olField to 0
  145.   set okButton to 0
  146.   set childWindowIDs to gMasterAppObject(mGetChildWindowIDs, olDialog)
  147.   if word 1 of childWindowIDs = "Error:" then
  148.     warning("tellNetscapeURL(): can't find children of Open Location dialog")
  149.     return "Error: tellNetscapeURL(): can't find children of Open Location dialog"
  150.   end if
  151.   set ncw to the number of words in childWindowIDs
  152.   if ncw >= 1 then
  153.     repeat with i = 1 to ncw
  154.       set thisIDText to word i of childWindowIDs
  155.       set thisID to integer(thisIDText)
  156.       if integerp(thisID) then
  157.         if gMasterAppObject(mWindowType, thisID) = "Edit" then
  158.           set olField to thisID
  159.         end if
  160.         if gMasterAppObject(mWindowName, thisID) = "Open" then
  161.           set okButton to thisID
  162.         end if
  163.       end if
  164.     end repeat
  165.   end if
  166.   if olField = 0 then
  167.     warning("tellNetscapeURL(): can't find location field of Open Location dialog")
  168.     return "Error: tellNetscapeURL(): can't find location field of Open Location dialog"
  169.   end if
  170.   if okButton = 0 then
  171.     warning("tellNetscapeURL(): can't find OK button of Open Location dialog")
  172.     return "Error: tellNetscapeURL(): can't find Open button of Open Location dialog"
  173.   end if
  174.   set nc to the number of chars in theURL
  175.   if nc > 1 then
  176.     repeat with i = 1 to nc
  177.       gMasterAppObject(mFakeCharacter, olField, char i of theURL)
  178.       set giveUpTicks to the ticks + 2
  179.       repeat while the ticks < giveUpTicks
  180.         gMasterAppObject(mFeedTimeSlice, theTask)
  181.         gMasterAppObject(mFeedGenericTimeSlice)
  182.       end repeat
  183.     end repeat
  184.     set theRect to gMasterAppObject(mGetWindowInsideRect, okButton)
  185.     set x to (integer(word 1 of theRect) + integer(word 3 of theRect)) / 2
  186.     set y to (integer(word 2 of theRect) + integer(word 4 of theRect)) / 2
  187.     gMasterAppObject(mFakeMouseClick, okButton, x, y)
  188.     set giveUpTicks to the ticks + 60
  189.     repeat while the ticks < giveUpTicks
  190.       gMasterAppObject(mFeedTimeSlice, theTask)
  191.       gMasterAppObject(mFeedGenericTimeSlice)
  192.     end repeat
  193.   end if
  194.   return 1
  195. end
  196.  
  197. on netscapeWindowIDs
  198.   global gMasterAppObject
  199.   if not insureMasterApp() then
  200.     warning("netscapeWindowIDs(): insureMasterApp() failed")
  201.     return []
  202.   end if
  203.   set taskIDs to getNamedTasks("Netscape")
  204.   set theCount to count(taskIDs)
  205.   if theCount < 1 then
  206.     warning("netscapeWindowIDs(): no Netscape tasks")
  207.     return []
  208.   end if
  209.   set windowIDs to []
  210.   repeat with i = 1 to theCount
  211.     set thisTaskID to getAt(taskIDs, i)
  212.     set thisWindowIDs to gMasterAppObject(mGetTaskWindowIDs, thisTaskID)
  213.     if word 1 of thisWindowIDs <> "Error:" then
  214.       set nw to the number of words in thisWindowIDs
  215.       if nw >= 1 then
  216.         repeat with j = 1 to nw
  217.           set thisWindowText to word j of thisWindowIDs
  218.           set thisWindowID to integer(thisWindowText)
  219.           if integerp(thisWindowID) then
  220.             if not gMasterAppObject(mWindowExists, thisWindowID) then
  221.               next repeat
  222.             end if
  223.             if not gMasterAppObject(mWindowHasChildren, thisWindowID) then
  224.               next repeat
  225.             end if
  226.             if gMasterAppObject(mWindowParent, thisWindowID) <> 0 then
  227.               next repeat
  228.             end if
  229.             if not (gMasterAppObject(mWindowName, thisWindowID) contains "Netscape") then
  230.               next repeat
  231.             end if
  232.             if not (gMasterAppObject(mWindowType, thisWindowID) contains "Afx:") then
  233.               next repeat
  234.             end if
  235.             add(windowIDs, thisWindowID)
  236.           end if
  237.         end repeat
  238.       end if
  239.     end if
  240.   end repeat
  241.   if count(windowIDs) < 1 then
  242.     warning("netscapeWindowIDs(): no Netscape windows")
  243.     return []
  244.   end if
  245.   return windowIDs
  246. end
  247.  
  248. on netscapeWindowID
  249.   set windowIDs to netscapeWindowIDs()
  250.   if count(windowIDs) > 1 then
  251.     warning("netscapeWindowID(): ambiguous: more than one Netscape window")
  252.     return 0
  253.   end if
  254.   if count(windowIDs) < 1 then
  255.     warning("netscapeWindowID(): no Netscape window")
  256.     return 0
  257.   end if
  258.   return getAt(windowIDs, 1)
  259. end
  260.  
  261. on killAllNetscapeTasks
  262.   global gMasterAppObject
  263.   if not insureMasterApp() then
  264.     warning("killAllNetscapeTasks(): insureMasterApp() failed")
  265.     return 0
  266.   end if
  267.   set taskIDs to getNamedTasks("Netscape")
  268.   set theCount to count(taskIDs)
  269.   if theCount < 1 then
  270.     return 1
  271.   end if
  272.   set windowIDs to []
  273.   repeat with i = 1 to theCount
  274.     set thisTaskID to getAt(taskIDs, i)
  275.     set thisWindowIDs to gMasterAppObject(mGetTaskWindowIDs, thisTaskID)
  276.     if word 1 of thisWindowIDs <> "Error:" then
  277.       set nw to the number of words in thisWindowIDs
  278.       if nw >= 1 then
  279.         repeat with j = 1 to nw
  280.           set thisWindowText to word j of thisWindowIDs
  281.           set thisWindowID to integer(thisWindowText)
  282.           if integerp(thisWindowID) then
  283.             if not gMasterAppObject(mWindowExists, thisWindowID) then
  284.               next repeat
  285.             end if
  286.             if not gMasterAppObject(mWindowHasChildren, thisWindowID) then
  287.               next repeat
  288.             end if
  289.             if gMasterAppObject(mWindowParent, thisWindowID) <> 0 then
  290.               next repeat
  291.             end if
  292.             if not (gMasterAppObject(mWindowName, thisWindowID) contains "Netscape") then
  293.               next repeat
  294.             end if
  295.             if not (gMasterAppObject(mWindowType, thisWindowID) contains "Afx:") then
  296.               next repeat
  297.             end if
  298.             add(windowIDs, thisWindowID)
  299.           end if
  300.         end repeat
  301.       end if
  302.     end if
  303.   end repeat
  304.   set theCount to count(windowIDs)
  305.   if theCount >= 1 then
  306.     set success to 1
  307.     set killed to 1
  308.     repeat with i = 1 to theCount
  309.       set thisWindowID to getAt(windowIDs, i)
  310.       set theTask to gMasterAppObject(mGetWindowTask, thisWindowID)
  311.       if not (gMasterAppObject(mWindowExists, thisWindowID) = 1) then
  312.         next repeat
  313.       end if
  314.       gMasterAppObject(mCloseWindow, thisWindowID)
  315.       set giveUpTicks to the ticks + (10 * 60)
  316.       set killed to 0
  317.       repeat while the ticks < giveUpTicks
  318.         if not (gMasterAppObject(mWindowExists, thisWindowID) = 1) then
  319.           set killed to 1
  320.           exit repeat
  321.         end if
  322.         gMasterAppObject(mFeedTimeSlice, theTask)
  323.         gMasterAppObject(mFeedGenericTimeSlice)
  324.       end repeat
  325.       if not killed then
  326.         warning("killAllNetscapeTasks(): ten second timeout while killing window " & i & " of  " & theCount)
  327.         set success to 0
  328.       end if
  329.     end repeat
  330.     if success <> 1 then
  331.       warning("killAllNetscapeTasks(): not all windows killed")
  332.       return 0
  333.     end if
  334.   end if
  335.   set giveUpTicks to the ticks + (10 * 60)
  336.   repeat while the ticks < giveUpTicks
  337.     set theTasks to getNamedTasks("Netscape")
  338.     set theCount to count(theTasks)
  339.     if theCount < 1 then
  340.       return 1
  341.     end if
  342.     repeat with i = 1 to theCount
  343.       set thisTask to getAt(theTasks, i)
  344.       gMasterAppObject(mRudeQuitTask, thisTask, 0)
  345.       gMasterAppObject(mFeedGenericTimeSlice)
  346.     end repeat
  347.   end repeat
  348.   warning("killAllNetscapeTasks(): ten-second timeout, not all tasks killed")
  349.   return 0
  350. end
  351.